<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<codelookup:codeCollection id="roleList" codeType="CODE_TYPE" filterName="CODE_FILTER" filterParams="ROLE_LIST"/>

<script type="text/javascript">
    function searchRecord() {
        var currentForm = document.forms["searchUserForm"];
        currentForm.elements["searchTO.userId"].value = currentForm.elements["searchTO.userId"].value.trim();
        currentForm.elements["searchTO.userName"].value = currentForm.elements["searchTO.userName"].value.trim();
        submitForm("searchUserForm", "search.action");
    }

    function addRecord() {
        submitForm("searchUserForm", "viewAdd.action");
    }

    function updateRecord(recordName) {
        var currentForm = document.forms["searchUserForm"];
        currentForm.elements["userModel.selectId"].value = recordName;
        submitForm("searchUserForm", "view.action");
    }


    function deleteRecord() {
        if (!atLeastOneRecordChecked('searchUserFormDiv')) {
            alert('<s:text name="label.select.atleast.one.record"/>');
        } else {
            if (window.confirm('<s:text name="label.confirm.delete"/>')) {
                submitForm("searchUserForm", "delete.action");
            }
        }
    }

    function back() {
        submitForm("searchUserForm", "../cases/clientSummary.action");
    }
</script>
<div id='searchUserFormDiv'>
<s:form name="searchUserForm" action="">
<s:hidden name="userModel.selectId" value=""/>
<table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
<tr>
    <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
        <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
    </td>
    <td valign="bottom" class="page_title_bg" width="96%"><span class="page_title"><s:text name="label.search.user"/></span></td>
</tr>
<tr>
<td class="subcontent">&nbsp;</td>
<td class="subcontent">
<table class="sectionBorder" width="100%">
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.userId'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:textfield name="searchTO.userId" maxLength="25"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.userName'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:textfield name="searchTO.userName" maxLength="25"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name='label.userRole'/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:select list="#attr.roleList" name="searchTO.userRole" listKey="codeId" listValue="codeDesc" headerKey=""
                  headerValue=""/>
    </td>
</tr>
<tr>
    <td class="txtData" colspan="3">
        <input type="button" class="button" value="<s:text name='label.search'/>" onclick="searchRecord();">
        <input type="button" class="button" value="<s:text name='label.add'/>" onclick="addRecord();">
        <input type="button" class="button" value="<s:text name='label.delete'/>" onclick="deleteRecord();">
    </td>
</tr>
<tr>
<td colspan="6">
<display:table name="helper" form="searchUserForm" uid="row" action="search.action">
<display:column titleKey="label.seq" width="3%" nowrap="nowrap">
    <s:property
            value="%{#attr.row_rowNum+(helper.pageNumber-1)*helper.objectsPerPage}"/>
</display:column>
<display:column width="2%">
    <s:checkbox name="resultList[%{#attr.row_rowNum-1}].selectId" fieldValue="%{#attr.row.userId}"/>
</display:column>
<display:column titleKey="label.userId" sortable="true" sortProperty="USER_ID" width="10%">
    <s:property value="%{#attr.row.userId}"/>
</display:column>
<display:column titleKey="label.userName" sortable="true" sortProperty="USER_NAME" width="10%">
    <a href="javascript:updateRecord('<s:property value="%{#attr.row.userId}"/>')">
        <s:property value="%{#attr.row.userName}"/> </a>
</display:column>
<display:column titleKey="label.userRole" sortable="true" sortProperty="USER_ROLE" width="10%">
    <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ROLE_LIST,${row.userRole}"/>
</display:column>
<display:column titleKey="label.userDept" sortable="true" sortProperty="USER_DEPT_ID" width="20%">
    <codelookup:codeDesc codeType="DEPT_LIST" codeId="${row.deptId}"/>
</display:column>
<display:column titleKey="label.recPermission" width="40%">
    <s:if test='#attr.row.userRole!="A"'>
    <s:set var="firstInd" value="true"/>
        <s:if test='#attr.row.permission1=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,01"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,01"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission2=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,02"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,02"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission3=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,03"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,03"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission4=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,04"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,04"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission5=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,05"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,05"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission6=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,06"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,06"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission7=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,07"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,07"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission8=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,08"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,08"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission9=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,09"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,09"/>
            </s:else>
        </s:if>
        <s:if test='#attr.row.permission10=="Y"'>
            <s:if test="firstInd">
                <s:set var="firstInd" value="false"/>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,10"/>
            </s:if>
            <s:else>
                <br>
                <li/><codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,10"/>
            </s:else>
        </s:if>
    </s:if>
</display:column>
</display:table>
</td>
</tr>
     <tr>
        <td class="txtData" align="left" width="100%" colspan="3">
            <input type="button" class="button" value="<s:text name='label.back'/>" onclick="back();">
        </td>
    </tr>    
</table>
</td>
</tr>
</table>
</s:form></div>
